local skel = fk.CreateSkill {
  name = "emo__qingcheng",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__qingcheng"] = "晴澄",
  [":emo__qingcheng"] = "锁定技，每当你使用或打出一张牌时，若你累计使用和打出牌的牌名字数之和为：3倍数，获得一张基本牌；5倍数，获得一张锦囊牌；8倍数，获得一张装备牌。",

  ["@emo__qingcheng"] = "晴澄",
}

local skel_spec = {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
      table.find({ 3, 5, 8 }, function(num)
        return player:getMark("@" .. skel.name) % num == 0
      end)
  end,
  ---@param player ServerPlayer
  on_use = function(self, event, target, player, data)
    local typeMap = { [3] = "basic", [5] = "trick", [8] = "equip" }
    local get = {}
    for _, num in ipairs({ 3, 5, 8 }) do
      if player:getMark("@" .. skel.name) % num == 0 then
        local randomCard = player.room:getCardsFromPileByRule(".|.|.|.|.|" .. typeMap[num], 1, "allPiles")
        if #randomCard > 0 then
          table.insert(get, randomCard[1])
        end
      end
    end
    if #get > 0 then
      player.room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonJustMove, skel.name, nil, false, player)
    end
  end,
}
skel:addEffect(fk.CardUsing, skel_spec)
skel:addEffect(fk.CardResponding, skel_spec)

local skel_refresh_spec = {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@" .. skel.name, Fk:translate(data.card.trueName, "zh_CN"):len())
  end,
}
skel:addEffect(fk.CardUsing, skel_refresh_spec)
skel:addEffect(fk.CardResponding, skel_refresh_spec)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@" .. skel.name, 0)
end)

return skel
